package vuelta.general.team;

import java.util.Locale;

import vuelta.general.BaseActivity;
import vuelta.general.R;
import vuelta.general.util.Commons;
import vuelta.general.util.GestioneStringhe;
import vuelta.general.util.web.WebViewGiro;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class DettagliCorridore extends BaseActivity {
	private String[] altezza;
	private String[] eta;
	private String[] peso;
	private String[] nazione;
	private String[] corridore;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dettagli_corridore);
		initToolbar();
		Intent intent = getIntent(); // l'intent di questa activity

		String pkg = getPackageName();

		String nomeCorridore = intent.getStringExtra(pkg + ".corridore");
		String position = intent.getStringExtra(pkg + ".position");

		altezza = Commons.getInstance().getAltezza();
		eta = Commons.getInstance().getEta();
		peso = Commons.getInstance().getPeso();
		nazione = Commons.getInstance().getNazione();
		corridore = Commons.getInstance().getCorridore();

		ImageView imageviewCorridore = (ImageView) findViewById(R.id.foto_corridore);
		ImageView imageview = (ImageView) findViewById(R.id.nazionalita);

		String nazionalita = GestioneStringhe.getInstance().adattaStringa(nazione[Integer.parseInt(position)]);
		int nazionalitaID = getResources().getIdentifier(nazionalita, "drawable", getPackageName());
		imageview.setImageResource(nazionalitaID);

		String fotoCorridore = GestioneStringhe.getInstance().adattaStringa(corridore[Integer.parseInt(position)]);
		int corridoreID = getResources().getIdentifier(fotoCorridore, "drawable", getPackageName());
		imageviewCorridore.setImageResource(corridoreID);

		TextView textview = (TextView) findViewById(R.id.dettagli_corridore);
		textview.setText("\n" + "  " + getResources().getString(R.string.Name_Racer) + ": "
				+ corridore[Integer.parseInt(position)] + "\n" + "  " + getResources().getString(R.string.Age_Racer)
				+ ": " + eta[Integer.parseInt(position)] + "\n" + "  "
				+ getResources().getString(R.string.Height_Racer) + ": " + altezza[Integer.parseInt(position)] + "\n"
				+ "  " + getResources().getString(R.string.Weight_Racer) + ": " + peso[Integer.parseInt(position)]
				+ "\n");

		/*
		 * TextView textView = (TextView) findViewById(R.id.link_web);
		 * textView.setMovementMethod(LinkMovementMethod.getInstance()); String
		 * queryWiki = "<a href=\'http://it.wikipedia.org/wiki/" +
		 * GestioneStringhe
		 * .getInstance().adattaStringaWiki(corridore[Integer.parseInt
		 * (position)]) + "'>  Wikipedia</a>";
		 * textView.setText(Html.fromHtml(queryWiki));
		 */

		/*
		 * TextView textViewTw = (TextView) findViewById(R.id.link_twitter);
		 * String queryTwi =
		 * GestioneStringhe.getInstance().controllaTwitter(corridore
		 * [Integer.parseInt(position)]); if (!(queryTwi.equals(""))) {
		 * textViewTw.setMovementMethod(LinkMovementMethod.getInstance());
		 * String queryTw = "<a href=\'http://" + queryTwi +
		 * " ' >Seguimi su Twitter</a> ";
		 * textViewTw.setText(Html.fromHtml(queryTw)); }
		 */

		ImageView imgViewW = (ImageView) findViewById(R.id.link_web);
		final String queryWiki = GestioneStringhe.getInstance()
				.adattaStringaWiki(corridore[Integer.parseInt(position)]);
		imgViewW.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// Intent intent = new Intent();
				// intent.setAction(Intent.ACTION_VIEW);
				// intent.addCategory(Intent.CATEGORY_BROWSABLE);
				// intent.setData(Uri.parse("http://it.wikipedia.org/wiki/"+queryWiki));
				// Intent intent = new Intent(DettagliCorridore.this,
				// WebViewCorridore.class);
				// intent.putExtra("url", "http://it.wikipedia.org/wiki/" +
				// queryWiki);
				// startActivity(intent);

				Intent intent = new Intent(DettagliCorridore.this, WebViewGiro.class);
				Locale locale = Locale.getDefault();
				if (locale.equals(Locale.ITALIAN) || locale.equals(Locale.ITALY)) {
					intent.putExtra("url", "http://it.wikipedia.org/wiki/" + queryWiki);
				} else {
					intent.putExtra("url", "http://en.wikipedia.org/wiki/" + queryWiki);
				}
				startActivity(intent);

			}
		});

		ImageView imgViewTw = (ImageView) findViewById(R.id.link_twitter);
		final String queryTwi = GestioneStringhe.getInstance().controllaTwitter(corridore[Integer.parseInt(position)]);
		if (queryTwi.equals("")) {
			imgViewTw.setVisibility(View.GONE);
		}
		imgViewTw.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// Intent intent = new Intent();
				// intent.setAction(Intent.ACTION_VIEW);
				// intent.addCategory(Intent.CATEGORY_BROWSABLE);
				// intent.setData(Uri.parse("http://" + queryTwi));
				// startActivity(intent);
				Intent intent = new Intent(DettagliCorridore.this, WebViewGiro.class);
				intent.putExtra("url", "http://" + queryTwi);
				startActivity(intent);
			}
		});

	}

}